<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="" prop="item">
        <el-input
          v-model="queryParams.item"
          placeholder="请输入item(款-大方向)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="图片地址" prop="picUrl">
        <el-input
          v-model="queryParams.picUrl"
          placeholder="请输入图片地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="" prop="shopId">
        <el-input
          v-model="queryParams.shopId"
          placeholder="请输入店铺id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="" prop="">
        <el-date-picker
          clearable
          v-model="queryParams.payDayStart"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="开始日期"
        >
        </el-date-picker>
        <el-date-picker
          clearable
          v-model="queryParams.payDayEnd"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="" prop="salesAmount">
          <el-input
            v-model="queryParams.salesAmount"
            placeholder="请输入销售金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="returnAmount">
          <el-input
            v-model="queryParams.returnAmount"
            placeholder="请输入退款金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="netSalesAmount">
          <el-input
            v-model="queryParams.netSalesAmount"
            placeholder="请输入净销售额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="totalSalesNumber">
          <el-input
            v-model="queryParams.totalSalesNumber"
            placeholder="请输入总销售件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="netSalesNumber">
          <el-input
            v-model="queryParams.netSalesNumber"
            placeholder="请输入净销售件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="returnBeforeShipmentNumber">
          <el-input
            v-model="queryParams.returnBeforeShipmentNumber"
            placeholder="请输入发货前退货件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="returnAfterShipmentNumber">
          <el-input
            v-model="queryParams.returnAfterShipmentNumber"
            placeholder="请输入发货后退货件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="totalReturnNumber">
          <el-input
            v-model="queryParams.totalReturnNumber"
            placeholder="请输入总退货件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="comprehensiveReturnRate">
          <el-input
            v-model="queryParams.comprehensiveReturnRate"
            placeholder="请输入综合退货率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="grossProfit">
          <el-input
            v-model="queryParams.grossProfit"
            placeholder="请输入毛利额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="grossProfitRate">
          <el-input
            v-model="queryParams.grossProfitRate"
            placeholder="请输入毛利率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="endingInventory">
          <el-input
            v-model="queryParams.endingInventory"
            placeholder="请输入期末库存"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="exhaustionRate">
          <el-input
            v-model="queryParams.exhaustionRate"
            placeholder="售罄率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="newTime">
          <el-date-picker
            clearable
            v-model="queryParams.newTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上架时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="firstLevelColumn">
          <el-input
            v-model="queryParams.firstLevelColumn"
            placeholder="请输入一级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="threeLevelColumn">
          <el-input
            v-model="queryParams.threeLevelColumn"
            placeholder="请输入三级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="">
          <el-input
            v-model="queryParams.firstPriceRangeNum"
            placeholder="请输入成交价格&lt;100数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="secondPriceRangeNum">
          <el-input
            v-model="queryParams.secondPriceRangeNum"
            placeholder="请输入100&lt;=成交价格&lt;150数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="thirdPriceRangeNum">
          <el-input
            v-model="queryParams.thirdPriceRangeNum"
            placeholder="请输入150&lt;=成交价格&lt;200数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="fourthPriceRangeNum">
          <el-input
            v-model="queryParams.fourthPriceRangeNum"
            placeholder="请输入200&lt;=成交价格&lt;250数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="fifthPriceRangeNum">
          <el-input
            v-model="queryParams.fifthPriceRangeNum"
            placeholder="请输入250&lt;=成交价格&lt;300数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="sixthPriceRangeNum">
          <el-input
            v-model="queryParams.sixthPriceRangeNum"
            placeholder="请输入300&lt;=成交价格&lt;350数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="seventhPriceRangeNum">
          <el-input
            v-model="queryParams.seventhPriceRangeNum"
            placeholder="请输入350&lt;=成交价格&lt;400数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="">
          <el-input
            v-model="queryParams.eighthPriceRangeNum"
            placeholder="请输入400&lt;=成交价格数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="sdNumber">
          <el-input
            v-model="queryParams.sdNumber"
            placeholder="请输入SD单件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="mjxNumber">
          <el-input
            v-model="queryParams.mjxNumber"
            placeholder="请输入MJX单件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="payDay">
          <el-date-picker
            clearable
            v-model="queryParams.payDay"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="payDateYear">
          <el-input
            v-model="queryParams.payDateYear"
            placeholder="请输入支付日期-年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="payDateMonth">
          <el-input
            v-model="queryParams.payDateMonth"
            placeholder="请输入支付日期-月"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="payDateDay">
          <el-input
            v-model="queryParams.payDateDay"
            placeholder="请输入支付日期-日"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="payDateWeek">
          <el-input
            v-model="queryParams.payDateWeek"
            placeholder="请输入业务日期-周"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item label="逻辑删除;0=未删除；1=已删除" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入逻辑删除;0=未删除；1=已删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>
    <timeSearch
      @getDateArr="getDateArr"
      @changDay="changDay"
      :timeArr="timeArr"
      :dayActive="this.dayActive"
      :dayLimit="1095"
    />
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:BiItemSaleDwd:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:BiItemSaleDwd:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:BiItemSaleDwd:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:BiItemSaleDwd:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          >同步</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <div ref="tableDom">
      <el-table
        v-loading="loading"
        :maxHeight="BiItemSaleDwdList.length ? tableHeight : 'auto'"
        :data="BiItemSaleDwdList"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column  width="140" type="selection" width="55" align="center" /> -->
        <el-table-column
          width="140"
          label="item销售明细ID"
          align="center"
          prop="id"
        />
        <el-table-column
          width="140"
          label="item(款-大方向)"
          align="center"
          prop="item"
        />
        <el-table-column
          width="140"
          label="图片地址"
          align="center"
          prop="picUrl"
          ><template slot-scope="scope">
            <image-preview :src="scope.row.picUrl" :width="40" :height="40" />
          </template>
        </el-table-column>
        <el-table-column
          width="140"
          label="店铺id"
          align="center"
          prop="shopId"
        />
        <el-table-column
          width="140"
          label="店铺名称"
          align="center"
          prop="shopName"
        />
        <el-table-column width="140" label="品牌" align="center" prop="brand" />
        <el-table-column
          width="140"
          label="销售金额"
          align="center"
          prop="salesAmount"
        />
        <el-table-column
          width="140"
          label="退款金额"
          align="center"
          prop="returnAmount"
        />
        <el-table-column
          width="140"
          label="净销售额"
          align="center"
          prop="netSalesAmount"
        />
        <el-table-column
          width="140"
          label="总销售件数"
          align="center"
          prop="totalSalesNumber"
        />
        <el-table-column
          width="140"
          label="净销售件数"
          align="center"
          prop="netSalesNumber"
        />
        <el-table-column
          width="140"
          label="发货前退货件数"
          align="center"
          prop="returnBeforeShipmentNumber"
        />
        <el-table-column
          width="140"
          label="发货后退货件数"
          align="center"
          prop="returnAfterShipmentNumber"
        />
        <el-table-column
          width="140"
          label="总退货件数"
          align="center"
          prop="totalReturnNumber"
        />
        <el-table-column
          width="140"
          label="综合退货率"
          align="center"
          prop="comprehensiveReturnRate"
        />
        <el-table-column
          width="140"
          label="毛利额"
          align="center"
          prop="grossProfit"
        />
        <el-table-column
          width="140"
          label="毛利率"
          align="center"
          prop="grossProfitRate"
        />
        <el-table-column
          width="140"
          label="期末库存"
          align="center"
          prop="endingInventory"
        />
        <el-table-column
          width="140"
          label="售罄率"
          align="center"
          prop="exhaustionRate"
        />
        <el-table-column
          width="140"
          label="上架时间"
          align="center"
          prop="newTime"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.newTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="140"
          label="一级"
          align="center"
          prop="firstLevelColumn"
        />
        <el-table-column
          width="140"
          label="三级"
          align="center"
          prop="threeLevelColumn"
        />
        <el-table-column
          width="140"
          label="成交价格&lt;100数量"
          align="center"
          prop="firstPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="100&lt;=成交价格&lt;150数量"
          align="center"
          prop="secondPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="150&lt;=成交价格&lt;200数量"
          align="center"
          prop="thirdPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="200&lt;=成交价格&lt;250数量"
          align="center"
          prop="fourthPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="250&lt;=成交价格&lt;300数量"
          align="center"
          prop="fifthPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="300&lt;=成交价格&lt;350数量"
          align="center"
          prop="sixthPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="350&lt;=成交价格&lt;400数量"
          align="center"
          prop="seventhPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="400&lt;=成交价格数量"
          align="center"
          prop="eighthPriceRangeNum"
        />
        <el-table-column
          width="140"
          label="SD单件数"
          align="center"
          prop="sdNumber"
        />
        <el-table-column
          width="140"
          label="MJX单件数"
          align="center"
          prop="mjxNumber"
        />
        <el-table-column
          width="140"
          label="支付日期"
          align="center"
          prop="payDay"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payDay, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="140"
          label="支付日期-年"
          align="center"
          prop="payDateYear"
        />
        <el-table-column
          width="140"
          label="支付日期-月"
          align="center"
          prop="payDateMonth"
        />
        <el-table-column
          width="140"
          label="支付日期-日"
          align="center"
          prop="payDateDay"
        />
        <el-table-column
          width="140"
          label="业务日期-周"
          align="center"
          prop="payDateWeek"
        />
        <!-- <el-table-column  width="140"
        label="逻辑删除;0=未删除；1=已删除"
        align="center"
        prop="isDelete"
      />
      <el-table-column  width="140"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['product:BiItemSaleDwd:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['product:BiItemSaleDwd:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
      </el-table>
    </div>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改TItem商品销售日报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="item(款-大方向)" prop="item">
          <el-input v-model="form.item" placeholder="请输入item(款-大方向)" />
        </el-form-item>
        <el-form-item label="图片地址" prop="picUrl">
          <el-input v-model="form.picUrl" placeholder="请输入图片地址" />
        </el-form-item>
        <el-form-item label="店铺id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="销售金额" prop="salesAmount">
          <el-input v-model="form.salesAmount" placeholder="请输入销售金额" />
        </el-form-item>
        <el-form-item label="退款金额" prop="returnAmount">
          <el-input v-model="form.returnAmount" placeholder="请输入退款金额" />
        </el-form-item>
        <el-form-item label="净销售额" prop="netSalesAmount">
          <el-input
            v-model="form.netSalesAmount"
            placeholder="请输入净销售额"
          />
        </el-form-item>
        <el-form-item label="总销售件数" prop="totalSalesNumber">
          <el-input
            v-model="form.totalSalesNumber"
            placeholder="请输入总销售件数"
          />
        </el-form-item>
        <el-form-item label="净销售件数" prop="netSalesNumber">
          <el-input
            v-model="form.netSalesNumber"
            placeholder="请输入净销售件数"
          />
        </el-form-item>
        <el-form-item label="发货前退货件数" prop="returnBeforeShipmentNumber">
          <el-input
            v-model="form.returnBeforeShipmentNumber"
            placeholder="请输入发货前退货件数"
          />
        </el-form-item>
        <el-form-item label="发货后退货件数" prop="returnAfterShipmentNumber">
          <el-input
            v-model="form.returnAfterShipmentNumber"
            placeholder="请输入发货后退货件数"
          />
        </el-form-item>
        <el-form-item label="总退货件数" prop="totalReturnNumber">
          <el-input
            v-model="form.totalReturnNumber"
            placeholder="请输入总退货件数"
          />
        </el-form-item>
        <el-form-item label="综合退货率" prop="comprehensiveReturnRate">
          <el-input
            v-model="form.comprehensiveReturnRate"
            placeholder="请输入综合退货率"
          />
        </el-form-item>
        <el-form-item label="毛利额" prop="grossProfit">
          <el-input v-model="form.grossProfit" placeholder="请输入毛利额" />
        </el-form-item>
        <el-form-item label="毛利率" prop="grossProfitRate">
          <el-input v-model="form.grossProfitRate" placeholder="请输入毛利率" />
        </el-form-item>
        <el-form-item label="期末库存" prop="endingInventory">
          <el-input
            v-model="form.endingInventory"
            placeholder="请输入期末库存"
          />
        </el-form-item>
        <el-form-item label="告罄率" prop="exhaustionRate">
          <el-input v-model="form.exhaustionRate" placeholder="请输入告罄率" />
        </el-form-item>
        <el-form-item label="上架时间" prop="newTime">
          <el-date-picker
            clearable
            v-model="form.newTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上架时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="一级" prop="firstLevelColumn">
          <el-input v-model="form.firstLevelColumn" placeholder="请输入一级" />
        </el-form-item>
        <el-form-item label="三级" prop="threeLevelColumn">
          <el-input v-model="form.threeLevelColumn" placeholder="请输入三级" />
        </el-form-item>
        <el-form-item label="成交价格&lt;100数量" prop="firstPriceRangeNum">
          <el-input
            v-model="form.firstPriceRangeNum"
            placeholder="请输入成交价格&lt;100数量"
          />
        </el-form-item>
        <el-form-item
          label="100&lt;=成交价格&lt;150数量"
          prop="secondPriceRangeNum"
        >
          <el-input
            v-model="form.secondPriceRangeNum"
            placeholder="请输入100&lt;=成交价格&lt;150数量"
          />
        </el-form-item>
        <el-form-item
          label="150&lt;=成交价格&lt;200数量"
          prop="thirdPriceRangeNum"
        >
          <el-input
            v-model="form.thirdPriceRangeNum"
            placeholder="请输入150&lt;=成交价格&lt;200数量"
          />
        </el-form-item>
        <el-form-item
          label="200&lt;=成交价格&lt;250数量"
          prop="fourthPriceRangeNum"
        >
          <el-input
            v-model="form.fourthPriceRangeNum"
            placeholder="请输入200&lt;=成交价格&lt;250数量"
          />
        </el-form-item>
        <el-form-item
          label="250&lt;=成交价格&lt;300数量"
          prop="fifthPriceRangeNum"
        >
          <el-input
            v-model="form.fifthPriceRangeNum"
            placeholder="请输入250&lt;=成交价格&lt;300数量"
          />
        </el-form-item>
        <el-form-item
          label="300&lt;=成交价格&lt;350数量"
          prop="sixthPriceRangeNum"
        >
          <el-input
            v-model="form.sixthPriceRangeNum"
            placeholder="请输入300&lt;=成交价格&lt;350数量"
          />
        </el-form-item>
        <el-form-item
          label="350&lt;=成交价格&lt;400数量"
          prop="seventhPriceRangeNum"
        >
          <el-input
            v-model="form.seventhPriceRangeNum"
            placeholder="请输入350&lt;=成交价格&lt;400数量"
          />
        </el-form-item>
        <el-form-item label="400&lt;=成交价格数量" prop="eighthPriceRangeNum">
          <el-input
            v-model="form.eighthPriceRangeNum"
            placeholder="请输入400&lt;=成交价格数量"
          />
        </el-form-item>
        <el-form-item label="SD单件数" prop="sdNumber">
          <el-input v-model="form.sdNumber" placeholder="请输入SD单件数" />
        </el-form-item>
        <el-form-item label="MJX单件数" prop="mjxNumber">
          <el-input v-model="form.mjxNumber" placeholder="请输入MJX单件数" />
        </el-form-item>
        <el-form-item label="支付日期" prop="payDay">
          <el-date-picker
            clearable
            v-model="form.payDay"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付日期-年" prop="payDateYear">
          <el-input
            v-model="form.payDateYear"
            placeholder="请输入支付日期-年"
          />
        </el-form-item>
        <el-form-item label="支付日期-月" prop="payDateMonth">
          <el-input
            v-model="form.payDateMonth"
            placeholder="请输入支付日期-月"
          />
        </el-form-item>
        <el-form-item label="支付日期-日" prop="payDateDay">
          <el-input v-model="form.payDateDay" placeholder="请输入支付日期-日" />
        </el-form-item>
        <el-form-item label="业务日期-周" prop="payDateWeek">
          <el-input
            v-model="form.payDateWeek"
            placeholder="请输入业务日期-周"
          />
        </el-form-item>
        <el-form-item label="逻辑删除;0=未删除；1=已删除" prop="isDelete">
          <el-input
            v-model="form.isDelete"
            placeholder="请输入逻辑删除;0=未删除；1=已删除"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import timeSearch from "@/views/chart/day/day.vue";
import {
  listBiSkuSaleDwd,
  getBiSkuSaleDwd,
  delBiSkuSaleDwd,
  addBiSkuSaleDwd,
  updateBiSkuSaleDwd,
} from "@/api/sku/BiSkuSaleDwd";
//--------导入token
import { getToken } from "@/utils/auth";
import {
  listBiItemSaleDwd,
  getBiItemSaleDwd,
  delBiItemSaleDwd,
  addBiItemSaleDwd,
  updateBiItemSaleDwd,
  insertBatchItemData,
} from "@/api/sku/BiItemSaleDwd";

export default {
  name: "BiItemSaleDwd",
  components: { timeSearch },
  data() {
    return {
      pjtUrl: process.env.VUE_APP_BASE_API,
      dayActive: 30,
      timeArr: [
        { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeGap: { startTime: "", endTime: "" },
      isOpen: false,
      //纵向滚动条
      tableHeight: "",
      //产品导入
      dialogVisible: false,
      Uploadopen: false,
      files: [],
      limit: 2,
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url:
          process.env.VUE_APP_BASE_API +
          "/product/BiOrigOrder/addnewBiOrigOrderProduct",
      },
      Upload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url:
          process.env.VUE_APP_BASE_API +
          "/product/BiOrigOrder/importBiOrigOrderProduct",
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // TItem商品销售日报表格数据
      BiItemSaleDwdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        item: null,
        picUrl: null,
        shopId: null,
        shopName: null,
        brand: null,
        salesAmount: null,
        returnAmount: null,
        netSalesAmount: null,
        totalSalesNumber: null,
        netSalesNumber: null,
        returnBeforeShipmentNumber: null,
        returnAfterShipmentNumber: null,
        totalReturnNumber: null,
        comprehensiveReturnRate: null,
        grossProfit: null,
        grossProfitRate: null,
        endingInventory: null,
        exhaustionRate: null,
        newTime: null,
        firstLevelColumn: null,
        threeLevelColumn: null,
        firstPriceRangeNum: null,
        secondPriceRangeNum: null,
        thirdPriceRangeNum: null,
        fourthPriceRangeNum: null,
        fifthPriceRangeNum: null,
        sixthPriceRangeNum: null,
        seventhPriceRangeNum: null,
        eighthPriceRangeNum: null,
        sdNumber: null,
        mjxNumber: null,
        payDay: null,
        payDateYear: null,
        payDateMonth: null,
        payDateDay: null,
        payDateWeek: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        item: [
          {
            required: true,
            message: "item(款-大方向)不能为空",
            trigger: "blur",
          },
        ],
        shopId: [
          { required: true, message: "店铺id不能为空", trigger: "blur" },
        ],
        shopName: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    var _this = this;
    this.resizeTable();
    window.onresize = function () {
      _this.resizeTable();
    };
  },
  //记得清空  如果在keepalive中 则使用activated  deactivated
  destroyed() {
    window.onresize = null;
  },
  methods: {
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //   this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传文件大小不能超过 100MB!");
      }
      return isLt2M;
    },
    //图片预览
    handlePictureCardPreview(file) {
      // this.picUrl = file.url
      // this.imageUrl = file.url;
      // this.dialogVisible = true;
    },

    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    upload() {
      this.Uploadopen = true;
    },
    handlePictureSuccessDaoru(res, file) {
      // = file.response.url;
      // console.log(JSON.stringify(this.file));
      if (res.code == 200) {
        this.$modal.msgSuccess("导入成功");

        this.dialogVisible = false;
        if (res.msg == "操作成功") {
          this.$modal.msgSuccess("导入成功");
        } else {
          this.$modal.msgError(res.msg);
        }
        this.getList();
        return true;
      } else {
        this.$modal.msgError(res.msg);
        this.dialogVisible = true;
        // this.$message.msgError('该颜色未在字典定义')
        return;
      }
    },
    handlePictureSuccessUpload(res, file) {
      // = file.response.url;
      // console.log(JSON.stringify(this.file));
      if (res.code == 200) {
        this.$modal.msgSuccess("导入成功");

        this.Uploadopen = false;
        if (res.msg == "操作成功") {
          this.$modal.msgSuccess("导入成功");
        } else {
          this.$modal.msgError(res.msg);
        }
        this.getList();
        return true;
      } else {
        this.$modal.msgError(res.msg);
        this.Uploadopen = true;
        // this.$message.msgError('该颜色未在字典定义')
        return;
      }
    },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接LOGO图片数量不能超过 ${this.limit} 个!`);
    },
    // 上传文件让第二次覆盖第一的文件
    changeFile1(file, fileList) {
      if (fileList.length > 1) {
        this.files = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
    handledeleteByPaymentPeriod() {
      // this.$modal.msgWarning("数据正在同步，请稍候")
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      deleteByPaymentPeriod(obj).then((res) => {
        this.$modal.msgWarning(res.msg);
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefreshCache() {
      // this.$modal.msgWarning("数据正在同步，请稍候");
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading();
      insertBatchItemData(obj).then(() => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess("数据已同步");
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //时间控件
    changDay(val) {
      this.dayActive = val;
      this.timeGap.startTime = val[0];
      this.timeGap.endTime = val[1];
    },
    getDateArr(value) {
      this.timeGap.startTime = value[0];
      this.timeGap.endTime = value[1];
      console.log(JSON.stringify(this.timeGap));
      this.queryParams.payDayStart = this.timeGap.startTime;
      this.queryParams.payDayEnd = this.timeGap.endTime;

      this.getList();

      this.dayActive = 1;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    // table自动高度
    returnTableHeight(ref, bottomOffset) {
      let height = null;
      height =
        window.innerHeight - ref.getBoundingClientRect().top - bottomOffset;
      return height;
    },

    resizeTable() {
      this.$nextTick(() => {
        this.tableHeight = this.returnTableHeight(this.$refs.tableDom, 100);
      }, 0);
    },
    /** 查询TItem商品销售日报列表 */
    getList() {
      this.loading = true;
      listBiItemSaleDwd(this.queryParams).then((response) => {
        this.BiItemSaleDwdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        item: null,
        picUrl: null,
        shopId: null,
        shopName: null,
        brand: null,
        salesAmount: null,
        returnAmount: null,
        netSalesAmount: null,
        totalSalesNumber: null,
        netSalesNumber: null,
        returnBeforeShipmentNumber: null,
        returnAfterShipmentNumber: null,
        totalReturnNumber: null,
        comprehensiveReturnRate: null,
        grossProfit: null,
        grossProfitRate: null,
        endingInventory: null,
        exhaustionRate: null,
        newTime: null,
        firstLevelColumn: null,
        threeLevelColumn: null,
        firstPriceRangeNum: null,
        secondPriceRangeNum: null,
        thirdPriceRangeNum: null,
        fourthPriceRangeNum: null,
        fifthPriceRangeNum: null,
        sixthPriceRangeNum: null,
        seventhPriceRangeNum: null,
        eighthPriceRangeNum: null,
        sdNumber: null,
        mjxNumber: null,
        payDay: null,
        payDateYear: null,
        payDateMonth: null,
        payDateDay: null,
        payDateWeek: null,
        isDelete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.queryParams.pageSize = 10;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加TItem商品销售日报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiItemSaleDwd(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改TItem商品销售日报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiItemSaleDwd(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiItemSaleDwd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除TItem商品销售日报编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiItemSaleDwd(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/BiItemSaleDwd/export",
        {
          ...this.queryParams,
        },
        `BiItemSaleDwd_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
